<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          @click="handleSearch"
          size="mini"
          v-hasPermi="['putStorage:halfCheck:query']"
        >
          查询
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          :disabled="single"
          icon="el-icon-circle-check"
          size="mini"
          @click="checkPodJyjg('OK')"
          v-hasPermi="['putStorage:halfCheck:permit']"
        >
          允收
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          icon="el-icon-scissors"
          :disabled="single"
          @click="checkPodJyjg('TC')"
          v-hasPermi="['putStorage:halfCheck:special']"
        >
          特采
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          icon="el-icon-circle-close"
          :disabled="single"
          @click="permitSpecialRefuse('NG')"
          v-hasPermi="['putStorage:halfCheck:refuse']"
        >
          拒收
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="single"
          @click="check_back = true"
          v-hasPermi="['putStorage:halfCheck:back']"
        >
          撤回开单
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAllJy"
          :disabled="single"
          v-hasPermi="['putStorage:halfCheck:allJy']"
        >
          一键检验
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:halfStart:export']"
        >
          Excel
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:putStorageAdd:export']"
        >
          入库明细
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['putStorage:putStorageAdd:export']"
        >
          入库统计
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      :height="tableH"
      :cell-style="iCellStyle"
      v-loading="loading"
      :data="RpmMstrList"
      @row-click="clickRows"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" width="40" type="index" align="center" />
      <el-table-column
        label="入库单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="rpmDjbh"
      />
      <el-table-column
        label="入库日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmRkrq"
        width="100"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rpmRkrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="入库类型"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmType"
      >
        <template #default="scope">
          <dict-tag :options="rpmTypeOptions" :value="scope.row.rpmType" />
        </template>
      </el-table-column>
      <el-table-column
        label="入库仓库"
        :show-overflow-tooltip="true"
        width="120"
        align="center"
        prop="rpmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.rpmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="班次"
        :show-overflow-tooltip="true"
        width="90"
        align="center"
        prop="rpmBcdm"
      />
      <el-table-column
        label="客户代码"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmKhdm"
      >
        <template #default="scope">
          <dict-tag :options="allCustomerOptions" :value="scope.row.rpmKhdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="开单人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmJlry"
      />
      <el-table-column
        label="检验结果"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmJyjg"
      >
        <template #default="scope">
          <dict-tag :options="jyjgOptions" :value="scope.row.rpmJyjg" />
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmDesc"
      />
      <el-table-column
        label="开单日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmJlrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.rpmJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="检验人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmJyry"
      />
      <el-table-column
        label="检验日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmJyrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.rpmJyrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rpmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rpmGzrq"
        width="180"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.rpmGzrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!--子表Tab-->
    <el-tabs v-model="activeTab">
      <el-tab-pane label="入库明细" name="first">
        <el-table
          border
          stripe
          :height="tableHChild"
          :cell-style="iCellStyle2"
          :data="rwdDetList"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column
            label="#"
            type="index"
            width="40"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="客户编号"
            width="135"
            align="center"
            prop="rpdCusWldm"
            fixed="left"
          />
          <el-table-column
            label="制造单号"
            width="135"
            align="center"
            prop="rpdZzdh"
          />
          <el-table-column
            label="机台"
            width="135"
            align="center"
            prop="rpdJtbh"
          />
          <el-table-column
            label="物料代码"
            width="135"
            align="center"
            prop="rpdWldm"
          />
          <el-table-column
            label="产品名称"
            width="135"
            align="center"
            prop="rpdWlpm"
          />
          <el-table-column label="产品规格" width="335" prop="rpdWlgg" />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="rpdDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.rpdDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            width="80"
            align="center"
            prop="rpdSqsl"
          />
          <el-table-column
            label="允收数量"
            width="80"
            align="center"
            prop="rpdOksl"
          />
          <el-table-column
            label="拒收数量"
            width="80"
            align="center"
            prop="rpdNgsl"
          />
          <el-table-column
            label="入库数量"
            width="80"
            align="center"
            prop="rpdRksl"
          />
          <el-table-column
            label="箱包装数"
            width="80"
            align="center"
            prop="rpdMxsl"
          />
          <el-table-column
            label="检验人员"
            width="80"
            align="center"
            prop="rpdJyry"
          />
          <el-table-column
            label="检验日期"
            width="80"
            align="center"
            prop="rpdJyrq"
          />
          <el-table-column
            label="备注"
            width="120"
            align="center"
            prop="rpdDesc"
          />
          <el-table-column
            label="检验结果"
            width="120"
            align="center"
            prop="rpdJyjg"
          />
          <el-table-column
            label="结果描述"
            width="120"
            align="center"
            prop="rpdJyms"
          />
          <el-table-column
            label="入库人员"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="rpdRkry"
          />
          <el-table-column
            label="入库日期"
            :show-overflow-tooltip="true"
            align="center"
            prop="rpdRkrq"
            width="150"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.rpdRkrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="100"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <el-button
                size="mini"
                type="text"
                :disabled="single"
                @click="handleCJy(scope.row)"
                v-hasPermi="['purchase:qgmMstr:remove']"
              >
                检验结果
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="入库统计" name="second">
        <el-table border stripe :height="tableHChild">
          <el-table-column label="#" width="40" align="center" />
          <el-table-column
            label="客户编号"
            show-overflow-tooltip
            align="center"
            prop="rpdCusWldm"
          />
          <el-table-column
            label="物料代码"
            show-overflow-tooltip
            align="center"
            prop="rpdWldm"
          />
          <el-table-column
            label="产品名称"
            show-overflow-tooltip
            align="center"
            prop="rpdWlpm"
          />
          <el-table-column
            label="产品规格"
            show-overflow-tooltip
            align="center"
            prop="rpdWlgg"
          />
          <el-table-column
            label="客户编码"
            show-overflow-tooltip
            align="center"
            prop="rpdCusWldm"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="60"
            align="center"
            prop="rpdDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.rpdDw" />
            </template>
          </el-table-column>
          <el-table-column label="最小包装" align="center" prop="itmMinbz" />
          <el-table-column label="包装数量" align="center" prop="rpdMxsl" />
          <el-table-column label="申请数量" align="center" prop="rpdSqsl" />
          <el-table-column label="允收数量" align="center" prop="rpdOksl" />
          <el-table-column label="拒收数量" align="center" prop="rpdNgsl" />
          <el-table-column label="入库数量" align="center" prop="rpdRksl" />
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="720px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="12">
          <el-form-item label="开单日期">
            <el-date-picker
              v-model="dateRange"
              :picker-options="pickerOptions"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库类型" prop="rpmType">
            <el-select
              v-model="queryParams.rpmType"
              class="input240"
              placeholder="请选择入库类型"
              clearable
              size="small"
            >
              <el-option
                v-for="dict in rpmTypeOptions"
                :key="dict.dictValue"
                :label="dict.dictLabel"
                :value="dict.dictValue"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库单号" prop="rpmDjbh">
            <el-input
              v-model="queryParams.rpmDjbh"
              placeholder="请输入入库单号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库仓库" prop="rpmCkdm">
            <el-select
              v-model="queryParams.rpmCkdm"
              style="width: 240px"
              clearable
              filterable
              placeholder="请选择仓库"
            >
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="综合查询" prop="integrated">
            <el-input
              type="textarea"
              v-model="queryParams.integrated"
              placeholder="输入物料代码或品名规格"
              clearable
              style="width: 520px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24" style="text-align: center">
          <el-form-item prop="rwmZtbz">
            <el-radio-group v-model="queryParams.rpmZtbz">
              <el-radio
                style="margin-right: 10px"
                v-for="dict in ZtbzOptions"
                :key="dict.dictValue"
                :label="dict.dictValue"
              >
                {{ dict.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 检验结果对话框   -->
    <el-dialog
      :title="title"
      v-model="open"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form ref="form" :model="form" label-width="88px" :rules="rules">
        <el-col :span="12">
          <el-form-item label="入库单号" prop="rwdDjbh">
            <el-input v-model="form.rpdDjbh" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="rwdWldm">
            <el-input v-model="form.rpdWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="检验结果" prop="rwdJyjg">
            <el-radio-group
              v-model="form.rpdJyjg"
              size="medium"
              @change="jyjgChange"
            >
              <el-radio
                v-for="(item, index) in jyjgOptions"
                :key="index"
                :label="item.dictValue"
                :disabled="item.disabled"
              >
                {{ item.dictLabel }}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="申请数量" prop="rwdSqsl">
            <el-input v-model="form.rpdSqsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="允收数量" prop="rwdOksl">
            <el-input v-model="form.rpdOksl" @input="handleInput" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="拒收数量" prop="rwdNgsl">
            <el-input
              type="number"
              v-model="form.rpdNgsl"
              @input="handleInput2"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="检验描述" prop="rwdJydecs">
            <el-input type="textarea" v-model="form.rpdJyms" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="jyjgSubmit">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 撤回开单对话框 -->
    <Modal v-model="check_back" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认撤回至开单？</span>
      </p>
      <div style="text-align: center">
        <p>撤回理由</p>
        <Input v-model="backRpmDesc" style="width: 75%" />
      </div>
      <div slot="footer">
        <Button type="error" size="large" long @click="handleBack">撤回</Button>
      </div>
    </Modal>
  </div>
</template>

<script>
import {
  listRpmMstr,
  listRpd,
  rpdAllJy,
  getRpdDet,
  checkRpdDet,
  backOrder,
  permitSpecialRefuse,
} from "@/api/putStorage/RpmMstr";
import { getAllCustomer, getAllCustomerTwo } from "@/api/project/customer";
import { getstorageType, getAll } from "@/api/repertory/Storage";
import { listBcm } from "@/api/base/bcm";

export default {
  name: "HalfCheck",
  data() {
    return {
      // 遮罩层
      loading: true,
      activeTab: "first",
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      tableH: (document.body.clientHeight - 130) / 2,
      tableHData: (document.body.clientHeight - 270) / 2,
      tableHChild: (document.body.clientHeight - 280) / 2,
      // 非单个禁用
      single: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 总条数
      total: 0,
      // rpmMstr 表格数据
      RpmMstrList: [],
      // rpdDet 统计/详细 表格数据
      rwdDetTotal: [],
      rwdDetList: [],
      // 弹出层标题
      title: "",
      //撤回原因
      backRpmDesc: null,
      // 是否显示弹出层
      open: false,
      check_back: null,
      // 入库类型字典
      rpmTypeOptions: [],
      // 所有客户代码字典
      allCustomerOptions: [],
      //所有仓库字典
      allStorageOptions: [],
      //有效
      storageOptions: [],
      //单位字典
      unitFlagOptions: [],
      //请求状态
      ZtbzOptions: [
        {
          dictLabel: "未检验",
          dictValue: "1",
        },
        {
          dictLabel: "已检验",
          dictValue: "2",
        },
        {
          dictLabel: "全部",

          dictValue: "",
        },
      ],
      //检验结果
      jyjgOptions: [
        {
          dictLabel: "允收",
          dictValue: "OK",
          listClass: "default",
        },
        {
          dictLabel: "拒收",
          dictValue: "NG",
          listClass: "default",
        },
        {
          dictLabel: "特采",
          dictValue: "TC",
          listClass: "default",
        },
      ],

      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      // 开单日期时间范围
      dateRange: [
        new Date(new Date().getTime() - 3600 * 1000 * 24 * 30),
        new Date(new Date().getTime() + 3600 * 1000 * 24 * 60),
      ],
      //选中的数据
      rowData: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        rpmDjbh: null,
        rpmType: null,
        rpmZtbz: "1",
        integrated: "",
        rpmTjflag: "1",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        rpdOksl: [
          { required: true, message: "允收数量不能为空", trigger: "blur" },
        ],
        rpdNgsl: [
          { required: true, message: "拒收数量不能为空", trigger: "change" },
        ],
        rpdJyjg: [
          { required: true, message: "检验结果不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    //获取入库类型字典
    this.getAllDicts("input_StorageType").then((response) => {
      this.rpmTypeOptions = response.data;
    });
    //单位
    this.getAllDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    //获取所有客户
    getAllCustomerTwo().then((response) => {
      for (let i of response.data) {
        i.dictLabel = "[" + i.cusCode + "] " + i.cusName;
        i.dictValue = i.cusCode;
        i.listClass = "default";
      }
      this.allCustomerOptions = response.data.concat([
        { dictValue: ".H", dictLabel: "海尔" },
        { dictValue: ".M", dictLabel: "美的" },
        { dictLabel: "所有客户", dictValue: "SY", listClass: "default" },
      ]);
    });

    //获取所有存储仓库
    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    //根据状态获取存储仓库
    getstorageType("0").then((response) => {
      this.storageOptions = response.data;

      for (let item of this.storageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });

    this.getList();
  },
  methods: {
    /** 颜色事件 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rpmZtbz == "1" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#0fac09";
      }
      //通过
      else if (row.rpmZtbz == "2" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#0323af";
      }
      //检验
      else if (row.rpmZtbz == "6" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#bb0331";
      }
      if (row.rpmZtbz == "2" && row.rpmTjflag == "1") {
        return "padding:0px 0;color:#bb0331";
      }
    },
    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      if (row.rpdJyms) {
        return "color:#bb0331";
      }
    },
    /** 查询成品/半成品入库列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.dateRange && "" != this.dateRange) {
        this.queryParams.params["beginRpmJlrq"] = this.moment(
          this.dateRange[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endRpmJlrq"] = this.moment(
          this.dateRange[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listRpmMstr(this.queryParams).then((response) => {
        this.RpmMstrList = [];
        this.rwdDetList = [];
        this.rwdDetTotal = [];
        this.RpmMstrList = this.RpmMstrList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRows(row);
        } else if (this.RpmMstrList != null && this.RpmMstrList.length > 0) {
          this.clickRows(this.RpmMstrList[0]);
        }
      });
    },
    /** 选中单据 */
    clickRows(row) {
      //获得选中的详细数据
      this.rowData = row;
      //获得当前单据的状态
      this.single = row == null || row.rpmZtbz != "1" || row.rpmTjflag != "1";
      //获得选中的详细数据
      this.getRwdDetList(row.rpmDjbh);
    },
    /** 获取RwdDet 数据*/
    getRwdDetList(rpdDjbh) {
      this.rwdDetList = [];
      this.rwdDetTotal = [];
      if (rpdDjbh != null && rpdDjbh != "") {
        listRpd(rpdDjbh).then((response) => {
          this.rwdDetList = response.data.detail;
          this.rwdDetTotal = response.data.total;
        });
      }
    },
    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
        listRpmMstr(this.queryParams).then((response) => {
          this.RpmMstrList = this.RpmMstrList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.backRwmDesc = null;
      this.check_back = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        rpdId: null,
        rpdDjbh: null,
        rpdZzdh: null,
        rpdJtbh: null,
        rpdWldm: null,
        rpdSqsl: null,
        rpmBcdm: null,
        rpdOksl: null,
        rpdNgsl: null,
        rpdJyjg: null,
        rpdJyms: null,
        rpdJyry: null,
        rpdJyrq: null,
        rpdRksl: null,
        rpdRkry: null,
        rpdRkrq: null,
        rpdMoeid: null,
        rpdMxsl: null,
        rpdDesc: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.RpmMstrList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleSearch() {
      this.reset();
      this.title = "查询成品/半成品入库";
      this.openSearch = true;
    },
    // 一键检验
    handleAllJy() {
      this.$confirm("一键检验选中的单据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        rpdAllJy(this.rowData.rpmDjbh)
          .then((res) => {
            this.queryParams.pageNum = 1;
            this.RpmMstrList = [];
            this.getList();
            this.msgSuccess("一键检验成功~");
          })
          .catch(() => {
            this.msgError("一键检验失败");
          });
      });
    },
    //检验结果
    handleCJy(row) {
      this.reset();
      const rpdId = row.rpdId;
      getRpdDet(rpdId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "检验结果";
      });
    },
    // 检验结果改变事件
    jyjgChange(val) {
      switch (val) {
        case "OK":
          this.form.rpdOksl = this.form.rpdSqsl;
          this.form.rpdNgsl = 0;
          break;
        case "TC":
          this.form.rpdOksl = this.form.rpdSqsl;
          this.form.rpdNgsl = 0;
          break;
        case "NG":
          this.form.rpdNgsl = this.form.rpdSqsl;
          this.form.rpdOksl = 0;
          break;
      }
    },
    //检验结果确定事件
    jyjgSubmit() {
      const data = this.form;
      checkRpdDet(data)
        .then((res) => {
          this.msgSuccess("检验成功~");
          this.cancel();
          this.getRwdDetList(this.rowData.rpmDjbh);
        })
        .catch(() => {
          this.msgError("检验失败~");
        });
    },
    handleInput(a) {
      this.form.rpdNgsl = this.$math.sub(this.form.rpdSqsl, a).internal;
    },
    handleInput2(a) {
      this.form.rpdOksl = this.$math.sub(this.form.rpdSqsl, a).internal;
    },
    /** 效验 rpdDet 是否检验 */
    is_empty() {
      if (this.rwdDetList.length > 0) {
        let flag = true; //效验该单据至少存在一个 检验结果为 :特采、允收
        for (let i of this.rwdDetList) {
          if (i.rpdJyjg === "" || i.rpdJyjg == null) return true;
          if (i.rpdJyjg == "OK" || i.rpdJyjg == "TC") flag = false;
        }

        return flag;
      } else {
        return true;
      }
    },
    //允收、特采 效验子项数据
    checkPodJyjg(type) {
      if (this.is_empty()) {
        this.$Modal.warning({
          title: "提示",
          content: "存在未输入检验结果或检验结果都为拒收的材料，不允许此操作",
        });
      } else {
        this.permitSpecialRefuse(type);
      }
    },
    //允收、特采、拒收
    permitSpecialRefuse(type) {
      let name = "";
      for (let i of this.jyjgOptions) {
        if (type == i.dictValue) {
          name = i.dictLabel;
          break;
        }
      }
      this.$confirm(
        "确认将【入库单号:" +
          this.rowData.rpmDjbh +
          "】的材料进行" +
          name +
          "作业吗?一旦操作无法更改，请谨慎操作。",
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      ).then(() => {
        permitSpecialRefuse(this.rowData.rpmId, type)
          .then((res) => {
            this.msgSuccess(name + "成功");
            this.queryParams.pageNum = 1;
            this.RpmMstrList = [];
            this.getList();
          })
          .catch(() => {
            this.msgError(name + "失败");
          });
      });
    },
    //撤回开单
    handleBack() {
      if (this.backRpmDesc == null || this.backRpmDesc == "") {
        this.msgError("请输入撤回理由~");
        return;
      }
      const data = {
        rpmId: this.rowData.rpmId,
        rpmDjbh: this.rowData.rpmDjbh,
        rpmJyjg: "",
        rpmDesc: this.backRpmDesc,
        rpmZtbz: 1,
        rpmTjflag: 0,
      };
      backOrder(data)
        .then((res) => {
          this.msgSuccess("撤回成功");
          this.queryParams.pageNum = 1;
          this.cancel();
          this.getList();
        })
        .catch(() => {
          this.msgError("撤回失败");
        });
    },
    /** 导出按钮操作 */
    handleExport() {},
  },
};
</script>

<style lang="scss" scoped></style>
